import java.util.Calendar;
import java.util.Date;

public class Calendar3 {
    public static void main (String [] args){
        System.out.println("===== date类转换为calendar实例 =====");
        //将date类转换为calendar实例
        Date d = new Date();
        d.setYear(1988-1900);
        System.out.println(d);
        Calendar c = Calendar.getInstance();
        c.setTime(d);
        //此方法将date实例设置到当前日历类，将date类转换为calendar
        System.out.println(c.getTime());
        //.getTime()将日历类实例，转换为date类实例
        System.out.printf("%tF %tT %tA %tp%n",c,c,c,c);
        System.out.printf("%tF %<tT %<tA %<tp%n",c);
        System.out.println("===== calendar类转换为date实例 =====");
        Calendar c2 = Calendar.getInstance();
        c2.set(Calendar.YEAR,1988);
        c2.set(Calendar.MONTH,4-1);
        c2.set(Calendar.DAY_OF_MONTH,20);
        System.out.println(c2.getTime());
        Date d1 = new Date();
        d1 = c2.getTime();
        //此方法将calendar类转换为date类
        System.out.println(d1);
        //格式化输出date类
        System.out.printf("%tF %tT %tA %tp%n",d1 ,d1,d1,d1);
        //格式化输出calendar类，
        System.out.printf("%tF %<tT %<tA %<tp%n",c2);
        //%tF日期：年月日
        //%tT时间：时分秒，而且会自动补零
        //%tA星期
        //%tp上午下午


    }
}
